<#assign object = doc.objects>
package ${object.package}.client;

import redora.rdo.client.ShowcasePanel;
import redora.rdo.client.upgrade.RedoraConfigurationViewPanel;
<#list object["/objects/object/name"] as objectName>
import ${object.package}.gwt.client.${objectName}ViewPanel;
</#list>
import ${object.package}.gwt.client.model.DataSourceFactory;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.DecoratedTabPanel;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Hyperlink;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.TabBar;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.smartgwt.client.widgets.layout.VLayout;

public class GWTShowcase implements EntryPoint {

	public void onModuleLoad() {

		final DecoratedTabPanel dataTp = new DecoratedTabPanel();
		<#list object["/objects/object/name"] as objectName>
		dataTp.add(new ${objectName}ViewPanel(), "${objectName?uncap_first}");
		</#list>
		dataTp.setHeight("500");
		dataTp.setWidth("100%");
		dataTp.selectTab(0);
		dataTp.setVisible(true);

		final DecoratedTabPanel attributeTp = new DecoratedTabPanel();
		<#list object["/objects/object/name"] as objectName>
		attributeTp.add(new AttributeFieldsView("${objectName}"), "${objectName?uncap_first}");
		</#list>
		attributeTp.setHeight("500");
		attributeTp.setWidth("100%");
		attributeTp.selectTab(0);
		attributeTp.setVisible(false);
		
		final FlowPanel upgradeFp = new FlowPanel();
		upgradeFp.add(new RedoraConfigurationViewPanel());
		upgradeFp.setVisible(false);

		// Create a tab bar with three items.
		TabBar bar = new TabBar();
		bar.setHeight("20");
		bar.setWidth("100%");
		bar.addTab("Model");
		bar.getTab(0).addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(false);
				attributeTp.setVisible(true);
				upgradeFp.setVisible(false);
			}

		});
		bar.addTab("Data");
		bar.getTab(1).addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(true);
				attributeTp.setVisible(false);
				upgradeFp.setVisible(false);
			}

		});
		bar.addTab("Upgrade");
		bar.getTab(2).addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(false);
				attributeTp.setVisible(false);
				upgradeFp.setVisible(true);
			}

		});
		bar.addTab("Tagging");
		bar.getTab(3).addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				dataTp.setVisible(false);
				attributeTp.setVisible(false);
				upgradeFp.setVisible(false);
			}

		});
		bar.addTab("SmartGWT for Demo!!");
		bar.getTab(4).addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent arg0) {
				VLayout layout = new ShowcasePanel(new DataSourceFactory());
				RootPanel.get().clear();
				layout.draw();
				RootPanel.get().add(layout);
			}

		});
		bar.selectTab(1);

		VerticalPanel panel = new VerticalPanel();
		panel.setHeight("1000");
		panel.setWidth("100%");

		RootPanel.get().add(panel);
		panel.add(bar);

		VerticalPanel showPanel = new VerticalPanel();

		showPanel.add(dataTp);
		showPanel.add(attributeTp);
		showPanel.setWidth("100%");
		showPanel.setHeight("100%");

		panel.add(showPanel);
		RootPanel.getBodyElement().removeChild(
				RootPanel.get("loadingWrapper").getElement());
	}

}